Currently, a machine to machine (M2M for short hereinafter) communications, namely, an Internet of Things technology, is extensively applied in more industries and fields, such as intelligent traffic, agricultural irrigation, and smart home industries. To meet application service requirements in different industries, an M2M system operator develops a unified M2M platform to implement some common capabilities, for example, data access and storage, data sharing and transmission, and group communication. The M2M platform may be accessed by different types of managed object devices (for example, sensors), and may provide a northbound application access interface, allowing application servers of different industries to invoke, by using the access interface, the common capabilities provided by the M2M platform.
For distributed transactions in an M2M system using a RESTful architecture, a transaction means that a task or operation needs to be completed by using multiple requests between an application server and managed object devices. The transaction is required to have atomicity (herein the atomicity means that the transaction is an indivisible work unit, and all operations included in the transaction should be executed to ensure execution integrity). In addition, in some scenarios of the M2M system in which a distributed transaction is committed, transaction resources on multiple servers require simultaneous execution. For example, in a scenario of intelligent irrigation including a water source and a large quantity of valves (these valves are managed object devices), which piece of farmland is irrigated and how much water is supplied are determined by opening/closing of a valve and an opening percentage. Specifically, a piece of land is divided into multiple plots; soil sensors that are deployed on the land and distributed in different plots collect degrees of water shortage in soil, and report collected data of water shortage of the soil to an M2M platform by using gateways deployed in different plots. By reading the data of the sensors on the M2M platform, an application server determines whether soil in each plot is currently short of water, and implements land irrigation by controlling opening/closing of a valve. Therefore, irrigation on one piece of land needs to be implemented by adjusting multiple valves, for example, opening a canal head valve, a submain pipe valve, a branch canal valve, and a branch pipe valve. These valves need to be opened simultaneously. Otherwise, if the canal head valve and the submain pipe valve are opened, but the branch canal valve is not opened, a branch canal is caused to overflow. Alternatively, at some thin pipes, an asynchronous adjustment of valves may cause abnormal pressure in the thin pipes, and cause joints to loosen or cause the pipes to deform, and so on.
The prior art provides a method for executing distributed transaction resources in the RESTful architecture, that is, a try-confirm/cancel (TCC for short hereafter) method. Specifically, an application server sends an update request to multiple managed object devices. Each update request carries an expiry time of the update request. A managed object device determines whether the managed object device meets a condition for executing the update request. If yes, the managed object device returns a success response to the application server, and waits for a commit request that is sent by the application server for the update request. If not, the managed object device returns a failure response to the application server, and the application server enters a rollback phase. After the application server receives a success response returned by each managed object device, the application server sends a commit request to each of the multiple managed object devices, so that the multiple managed object devices execute the update request, that is, complete execution of transaction resources, and enter a final state. If a managed object device fails to receive, before the expiry time arrives, the commit request sent by the application server, the update request previously received is automatically canceled, so that the managed object device returns to an initial state.
However, in the method provided by the prior art, because there is a delay in receiving the commit request by each managed object device, the multiple managed object devices cannot simultaneously execute the transaction resources (that is, cannot simultaneously execute the update request). Consequently, reliability of the distributed system is affected. In addition, in the prior art, at least two requests (the foregoing update request and commit request) are required between a transaction coordinator and a server before a transaction can be completed, and signaling overheads of the transaction are relatively high.